﻿using StudySystem.MainLogic.Items;
using StudySystem.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudySystem.MainLogic.FormControl
{
    public class FormQuesControl
    {
        public static void ShowQuestions(FlowLayoutPanel f, List<ClassQuestion> questions)
        {
            if(questions != null && questions.Count > 0)
            {
                foreach (ClassQuestion q in questions)
                {
                    Question question = new Question(q);
                    f.Controls.Add(question);
                    
                }
            }
            
        }

        public static void RenewQuestion(FlowLayoutPanel flp, List<ClassQuestion> questions)
        {
            FormController.DeleteElement(flp);
            ShowQuestions(flp, questions);
        }

        public static void DeleteAQuestion(FlowLayoutPanel flp, Question q)
        {

            flp.Controls.Remove(q);
        }

        public static void ModifyAQuestion(Question q, string newQuestion, string newAnswer)
        {
            q.SetQuestionRichTextBox(newQuestion);
            q.SetAnswerRichTextBox(newAnswer);
        }

        public static void SubmitARecord(Question question)
        {
            GroupBox groupBox = question.gboxAnswerCase;
            foreach (RadioButton rdo in groupBox.Controls)
            {
                if (rdo.Checked)
                {
                    ClassRecord.InsertARecord(question.Ques, (AnswerResult)rdo.Tag);
                }
            }
        }

        public static void SubmitRecords(FlowLayoutPanel flp)
        {
            foreach (Question q in flp.Controls)
            {
                SubmitARecord(q);
            }
        }
    }
}
